﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace EETOP.OAuthSDK
{
    /// <summary>
    /// A simple consumer which minimally implements IConsumer.
    /// </summary>
    [DebuggerDisplay("Key: {Key} Secret: {Secret} Status: {Status}")]
    public class OAuthConsumer
        : IConsumer
    {
        /// <summary>
        /// Creates a consumer with the given key and secret. The status will
        /// be Unknown.
        /// </summary>
        /// <param name="key">The consumer key</param>
        /// <param name="secret">The consumer secret</param>
        public OAuthConsumer(string key, string secret)
            : this(key, secret, "Unnamed consumer", ConsumerStatus.Unknown)
        {
        }

        /// <summary>
        /// Creates a consumer with the given key and secret. The status will
        /// be Unknown.
        /// </summary>
        /// <param name="key">The consumer key</param>
        /// <param name="secret">The consumer secret</param>
        /// <param name="friendlyName">The consumer's friendly name</param>
        public OAuthConsumer(string key, string secret, string friendlyName)
            : this(key, secret, friendlyName, ConsumerStatus.Unknown)
        {
        }

        /// <summary>
        /// Creates a consumer with the given key, secret and status.
        /// </summary>
        /// <param name="key">The consumer key</param>
        /// <param name="secret">The consumer secret</param>
        /// <param name="friendlyName">The consumer's friendly name</param>
        /// <param name="status">The status of the consumer</param>
        public OAuthConsumer(string key, string secret, string friendlyName, ConsumerStatus status)
        {
            this.Key = key;
            this.Secret = secret;
            this.FriendlyName = friendlyName;
            this.Status = status;
        }

        /// <summary>
        /// The consumer key (this MUST be unique across all consumers)
        /// </summary>
        public string Key
        {
            get;
            set;
        }

        /// <summary>
        /// The consumer secret
        /// </summary>
        public string Secret
        {
            get;
            set;
        }

        /// <summary>
        /// The status of the consumer
        /// </summary>
        public ConsumerStatus Status
        {
            get;
            set;
        }

        /// <summary>
        /// The name of the consumer. Service providers may choose to expose
        /// this to users.
        /// </summary>
        public string FriendlyName
        {
            get;
            set;
        }

        public override bool Equals(object obj)
        {
            if (obj == null)
                return false;

            if (System.Object.ReferenceEquals(this, obj))
                return true;

            if (this.GetType() != obj.GetType())
                return false;

            return this.Equals(obj as OAuthConsumer);
        }

        public bool Equals(OAuthConsumer other)
        {
            return other != null
                && string.Equals(this.Key, other.Key)
                && string.Equals(this.Secret, other.Secret)
                && this.Status == other.Status;
        }

        public override int GetHashCode()
        {
            return this.Key.GetHashCode() ^ this.Secret.GetHashCode() ^ this.Status.GetHashCode();
        }
    }
}
